package com.tangly.codeing.controller;

import org.springframework.web.bind.annotation.*;
import com.tangly.codeing.model.${classInfo.className};
import com.tangly.codeing.service.${classInfo.className}Service;
import com.tangly.codeing.utils.PageInfo;
import com.tangly.codeing.utils.ReturnT;

import javax.annotation.Resource;
import java.util.Arrays;

/**
 * ${classInfo.classComment}
 * @author tangbing
 * @date ${.now?string('yyyy-MM-dd')}
 */
@RestController
@RequestMapping("${classInfo.className?uncap_first}")
public class ${classInfo.className}Controller extends BaseController{

    @Resource
    private ${classInfo.className}Service ${classInfo.className?uncap_first}Service;

    /**
    * 新增
    */
    @PostMapping("/insert")
    public ReturnT<String> insert(@RequestBody ${classInfo.className} ${classInfo.className?uncap_first}){
        return ${classInfo.className?uncap_first}Service.insert(${classInfo.className?uncap_first});
    }

    /**
    * 删除
    */
    @DeleteMapping("/delete/{id}")
    public ReturnT<String> delete(@PathVariable("id") Long id){
        return ${classInfo.className?uncap_first}Service.delete(id);
    }

    /**
    * 批量删除
    */
    @PostMapping("/batchDelete")
    public ReturnT<String> batchDelete(@RequestParam("ids") String ids) {
       String[] split = ids.split(",");
       return ${classInfo.className?uncap_first}Service.batchDelete(Arrays.asList(split));
    }

    /**
    * 更新
    */
    @PostMapping("/update")
    public ReturnT<String> update(@RequestBody ${classInfo.className} ${classInfo.className?uncap_first}){
        return ${classInfo.className?uncap_first}Service.update(${classInfo.className?uncap_first});
    }

    /**
    * Load查询
    */
    @GetMapping("/load/{id}")
    public ReturnT<Object> load(@PathVariable("id") Long id){
        return new ReturnT<>(${classInfo.className?uncap_first}Service.load(id));
    }

    /**
    * 分页查询
    */
    @PostMapping("/pageList")
    public ReturnT<Object> pageList(@RequestBody PageInfo pageInfo) {
        ReturnT<Object> validateRes = validateParam(pageInfo);
        if (validateRes != null) {
            return validateRes;
        }
        return new ReturnT<>(${classInfo.className?uncap_first}Service.pageList(pageInfo));
    }

}
